package com.qfedu.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qfedu.bean.Customer;
import com.qfedu.dao.CustomerMapper;
import com.qfedu.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author 李小毅
 * @Description
 * @Date 2022-06-15
 */

@Service
public class CustomerServiceImpl implements CustomerService {

    @Autowired
    private CustomerMapper customerMapper;

    public void insertCustomer(Customer customer) {
        customerMapper.insertCustomer(customer);
    }

    public void updateCustomer(Customer customer) {
        if (customer.getId()!= null){
            customerMapper.updateCustomer(customer);
        }else {
            //TODO 我们更新是依据id更新 如果id没有返回 需提示用户
        }
    }

    public void delCustomerById(Integer id) {

        if (id != null){
            customerMapper.delCustomerById(id);
        }else {
            //TODO 我们删除是依据id更新 如果id没有返回 需提示用户
        }
    }

    public Customer getCustomerById(Integer id) {
        if (id != null){
            return customerMapper.getCustomerById(id);
        }else {
            //TODO 我们删除是依据id更新 如果id没有返回 需提示用户
            return null;
        }
    }

    public List<Customer> getAllCustomer() {
        return customerMapper.getAllCustomer();
    }

    public PageInfo<Customer> getAllCustomerByPage(Integer page,Integer limit) {
        //开启分页
        PageHelper.startPage(page,limit);
        List<Customer> customerList = customerMapper.getAllCustomer();

        return new PageInfo<Customer>(customerList);
    }


    public void deleteCustomersByIds(long[] ids) {

        customerMapper.deleteCustomersByIds(ids);
    }
}
















